require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#postRecycling",
    data:{
        loadFlag:false,
        delType:1,
        loginUid:userInfo.id,
        pageNumber:1,
        isScreen:"",
        delPosts:{},//回收帖子列表
        delPosts1:[],
        delPosts2:[]
    },
    mounted:function(){
        this.myDelPosts();
        // this.myRepliesPosts();
    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
            // if(this.square==1){
            //     location.href="/friend/circleSquare";
            // }else{
            //     location.href="/friend?indexs=3";
            // }
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //tab切换
        getTab:function(num){
            this.delType=num;
            this.pageNumber=1;
            this.myDelPosts();
        },
        //我的回收站帖子
        myDelPosts:function(){
            var that=this;
            var data={
                // loginUid:1,
                loginUid:userInfo.id,
                pageNumber:that.pageNumber,
                delType:that.delType
            };
            console.log(data);
            this.ajax({url:"/friend/myDelPosts",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.delPosts=b.json.data;
                    that.delPosts1=that.delPosts.list;
                    if(that.delPosts.pageNumber>1){
                        if(that.delPosts.list.length>0) {
                            that.delPosts2 = that.delPosts2.concat(b.json.data.list);
                        }
                    }else{
                        that.delPosts2=that.delPosts1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.delPosts={};
                    that.delPosts1=[];
                    that.delPosts2=[];
                    vm.$refs.prompt.toast("获取列表失败！");
                }
            });
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.delPosts.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            vm.myDelPosts();
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};